package deom1;

public class Test {

    public static String binaryAdd(String A, String B) {
        StringBuilder stringBuilder = new StringBuilder();
        int Alen = A.length();
        int Blen = B.length();
        int max = Alen > Blen ? Alen : Blen;

        StringBuilder s1 = new StringBuilder(A).reverse();
        StringBuilder s2 = new StringBuilder(B).reverse();
        boolean bool = false;

        for (int i = 0; i < max; i++) {
            char a = i >= Alen ? '0' : s1.charAt(i);
            char b = i >= Blen ? '0' : s2.charAt(i);

            if (a == '1' && b == '1') {
                stringBuilder.append(bool ? '1' : '0');
                bool = true;
            } else if (a == '0' && b == '0') {
                stringBuilder.append(bool ? '1' : '0');
                bool = false;
            } else {
                stringBuilder.append(bool ? '0' : '1');
            }
        }
        if(bool == true) {
            stringBuilder.append('1');
        }
        stringBuilder.reverse();
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        binaryAdd("1","11");
    }
}

